package com.hitrust.gs.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import com.hitrust.gs.business.GSProviderType;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;

public class GsProviderTypeDao extends GSBaseDAO {

	public boolean save(GSProviderType providerType) throws SQLException{	
		return this.executeUpdate("insert into T_PROVIDER_TYPE(ID, PROVIDER_ID, PROVIDER_CODE, PROVIDER_TYPE,STATUS) values(sys_guid(), ?, ?, 1,1)", 
				new Object[]{providerType.getProviderId(), providerType.getProviderCode()});
	}
	
	public boolean update(GSProviderType providerType) throws SQLException{
		return this.executeUpdate("update T_PROVIDER_TYPE set PROVIDER_TYPE=?, status=? where PROVIDER_CODE=?", 
				new Object[]{providerType.getProviderType(), providerType.getStatus(), providerType.getProviderCode()});
	}
	
	public boolean delete(Connection con, String providerCode) throws SQLException{	
		return this.executeUpdate(con, "update T_PROVIDER_TYPE set status=0 where PROVIDER_CODE=?", 
				new Object[]{providerCode});
	} 
	
	public boolean setAvailability(Connection con, String providerCode) throws SQLException{	
		return this.executeUpdate(con, "update T_PROVIDER_TYPE set status=1 where PROVIDER_CODE=?", 
				new Object[]{providerCode});
	} 
	
	public GSProviderType find(String providerCode) throws GSException{
		GSProviderType providerType = null;;
	        String tSql = "select * from T_PROVIDER_TYPE where PROVIDER_CODE=?";
	        Object tObj[] = {providerCode};
	        try{
	            ArrayList tList = this.executeQuery(new GSProviderType(),tSql,tObj);
	            if(tList.size() > 0){
	            	providerType =(GSProviderType)tList.get(0);
	            }
	        }catch(Exception e){
	            GSLogWriter.error(this, e.toString());
	            throw new GSException(GSException.E19999, GSException.E19999_MSG);
	        }
	        return providerType;
	}
}
